﻿[#include "/app/common/layout/__backstagemainlayout.html"/]

[#assign pageJavascript]
<script>
$(document).ready(function(){
	$("#doedituser").click(function(){
		var roles = new Array();
		$("input[name='roles']:checked").each(function(i){ 
			roles[i]=$(this).val(); 
		});  
		$.ajax({
			type:"post",
			url:"${ContextPath}/admin/doedituser",
			data:{
				"userid":$('#userid').val(),
				"uphone":$('#uphone').val(),
				"uemail":$('#uemail').val(),
				"roles":roles,
				"selectBranch":$('#selectBranch').val(),
				"selectApartment":$('#selectApartment').val(),
				"selectPosition":$('#selectPosition').val()},
			success:function(msg){
				alertModal(msg.state);
				$('#alertModal').modal();
				if(msg.state=='提交成功！'){
					window.location.href='${ContextPath}/admin/user'
				}
			}
		});
	});
});

function select1() {
	var papartid=$('#papartid').val();
	$.ajax(
    {
    	type: "post",
    	url: "${ContextPath}/admin/handler",
    	data: { "type": "afacher" },
        success: function (msg) {
        	$("#selectFapartment").append("<option value='-1'>请选择一级部门</option>");
        	for (var i = 0; i < msg.afacherList.length; i++) {
            	
            	if(msg.afacherList[i].id==papartid){
            		$("#selectFapartment").append("<option value=" + msg.afacherList[i].id + " selected='selected'>" + msg.afacherList[i].name +"</option>");
            	}else{
            		$("#selectFapartment").append("<option value=" + msg.afacherList[i].id + ">" + msg.afacherList[i].name +"</option>");
            	}
        	}
            select2();
        }
	})
};
function select2() {
	var apartid=$('#apartid').val();
	var positionid=$('#positionid').val();
	$("#selectApartment").html("");
	$("#selectPosition").html("");
	$.ajax(
	{
		type: "post",
		url: "${ContextPath}/admin/handler",
		data: { "type": "achilren","typeid":$('#selectFapartment').val() },
		success: function (msg) {
			$("#selectApartment").append("<option value='-1'>请选择二级部门</option>");
			$("#selectPosition").append("<option value='-1'>请选择职位</option>");
			for (var i = 0; i < msg.achilrenList.length; i++) {
				if(msg.achilrenList[i].id==apartid){
					$("#selectApartment").append("<option value=" + msg.achilrenList[i].id + " selected='selected'>" +msg.achilrenList[i].name +"</option>");
				}else{
					$("#selectApartment").append("<option value=" + msg.achilrenList[i].id + ">" +msg.achilrenList[i].name + "</option>");
				}
			}
			for (var i = 0; i < msg.pList.length; i++) {
				if(msg.pList[i].id==positionid){
					$("#selectPosition").append("<option value=" + msg.pList[i].id + " selected='selected'>" +msg.pList[i].name +"</option>");
				}else{
					$("#selectPosition").append("<option value=" + msg.pList[i].id + ">" +msg.pList[i].name + "</option>");
				}
			}
		}
	})
};

$(function(){
	select1();
	$('#selectFapartment').bind("change", select2);
});

function alertModal(msg){
	$("#modal-title-content").html("提示!");  
	$("#modal-body-content").html(msg);  
}

</script>
[/#assign]

[@mainlayout pageJavascript=pageJavascript pageCss=pageCss currentMenu="organizationFlag-userFlag-usersListFlag"]

<div class="page-header">
	<h1>
		<a href="${ContextPath}/admin/user">用户管理</a>
		<small> <i class="ace-icon fa fa-angle-double-right"></i> 编辑用户</small>
	</h1>
</div>

	<div class="form-horizontal"  >
		<div class="row">
			<input id="userid" type="hidden" name="userid" value="${(userinfo.uuserid)}">
			<input id="papartid" type="hidden" name="papartid" value="${(papartment.id)}">
			<input id="apartid" type="hidden" name="apartid" value="${(userinfo.info_apartmentid)}">
			<input id="positionid" type="hidden" name="positionid" value="${(userinfo.info_positionid)}">
			<div class="form-group">
				<label class="col-sm-2 control-label">姓名</label>
				<div class="col-sm-4">
					<input type="text" class="form-control"  name="ufullname" value="${(userinfo.ufullname)!}" readonly/>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label">联系方式</label>
				<div class="col-sm-4">
					<input id="uphone" type="text" class="form-control"  name="uphone" value="${(userinfo.uphone)!}"  autofocus/>
				</div>
				<div class="col-xs-4">
				[#if phoneMsg??]
					<div class="index-alert index-alert-danger" style="background-image:none;">
					${(phoneMsg)!}
					</div>
				[/#if]
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label">邮箱地址</label>
				<div class="col-sm-4">
					<input id="uemail" type="text" class="form-control"  name="uemail" value="${(userinfo.uemail)!}" />
				</div>
				<div class="col-xs-4">
				[#if emailMsg??]
					<div class="index-alert index-alert-danger" style="background-image:none;">
					${(emailMsg)!}
					</div>
				[/#if]
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label">单位</label>
				<div class="col-sm-4">
					<select id="selectBranch" name="selectBranch" class="form-control"  required >
						<option value="-1" selected="selected">请选择</option>
						[#list branchList as branch]
						[#if (userinfo.info_branchid)=branch.id]
						<option value="${(branch.id)!}" selected="selected">${(branch.name)!}	</option>
						[#else]
						<option value="${(branch.id)!}" >${(branch.name)!}	</option>
						[/#if]
						[/#list]
					</select>
				</div>
			</div>

			<div class="form-group">
				<label class="col-xs-2 control-label">部门</label>
				<div class="col-sm-2">
					<select id="selectFapartment" name="selectFapartment" class="form-control" required >
					</select>
				</div>
				<div class="col-sm-2">
					<select id="selectApartment" name="selectApartment" class="form-control" required>
					</select>
				</div>
			</div>
			
			<div class="form-group">
				<label class="col-sm-2 control-label">职位</label>
				<div class="col-sm-4">
					<select id="selectPosition" name="selectPosition" class="form-control"  required >
					</select>
				</div>
			</div>
			<div class="control-group">
				<label class="col-sm-2 control-label">角色类型</label>
				<div class="col-sm-4">
						[#list roleList as role]
							<div class="checkbox">
						    <label class="checkbox inline">
						    <input id="roles"   type="checkbox"  name="roles" value="${(role.id)!}"
							    [#list userrole as r]
							    	[#if r.roleid=role.id]
							    	 checked
							    	[/#if]
							    [/#list]
						    
						    > ${(role.name)!}
						    </label>
						    </div>
					    [/#list]

				</div>
			</div>
				<div class="control-group">
					<div class="col-sm-offset-2 col-sm-10">
						<button id="doedituser" name="edituser" value="提交"  class="btn btn-sm btn-primary save" data-loading-text="正在提交...">提交</button>
					</div>
				</div>
		</div>
	</div>
[#include "/app/admin/_model.html" /]
[/@mainlayout]